package org.smr.ministore.controller;

import javax.annotation.Resource;

import org.blade.msg.Message;
import org.blade.utils.Pager;
import org.smr.ministore.entities.GoodsSpecification;
import org.smr.ministore.entities.vo.Assign2OrganVO;
import org.smr.ministore.entities.vo.Assign2OrgansVO;
import org.smr.ministore.service.GoodsSpecificationService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestBody;


@Controller("GoodsSpecificationController")
public class GoodsSpecificationController {

	@Resource(name = "goodsSpecificationServiceImpl")
	private GoodsSpecificationService service;
	
	/**
	 * 保存编辑后的GoodsSpecification信息
	 * @param goodsSpecification
	 * @return
	 */
	@ResponseBody
	@RequestMapping(method = RequestMethod.PATCH, value = "/GoodsSpecification/edit")
	public Message modify(@RequestBody GoodsSpecification goodsSpecification){
		Message msg = new Message();
		
		if(null == goodsSpecification.getId()){
			msg.setStatus(service.save(goodsSpecification));
		}else{
			msg.setStatus(service.updateById(goodsSpecification));
		}
		return msg;
	}
	
	/**
	* 跳转到列表查询GoodsSpecification
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET, value = "/GoodsSpecification/list-page")
	public String toList(){
		return "/GoodsSpecification/GoodsSpecification-list";
	}

	/**
	*  根据id查询GoodsSpecification
	* @return
	*/
	@ResponseBody
	@RequestMapping(method = RequestMethod.GET, value = "/GoodsSpecification")
	public GoodsSpecification get( Long id ){
		return service.queryById(id);
	}


    /**
	 * 分页查询GoodsSpecification信息
	 * @param goodsSpecification
	 * @param pageSize
	 * @param pageNum
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value = "/GoodsSpecification/list")
	public Pager<GoodsSpecification> list(@RequestBody GoodsSpecification goodsSpecification , long pageSize, long pageNum ){

		return service.paginate(goodsSpecification, pageSize, pageNum);

	}
	
	
	/**
	 * 根据ID删除GoodsSpecification信息
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value = "/GoodsSpecification/remove",method = RequestMethod.DELETE)
	public Message remove( Long id){
		
		Message msg = new Message();
		msg.setStatus(service.deleteById(id));
		return msg;
	}

	/**
	 * 根据ID删除Goods信息
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value = "/GoodsSpecification/removeByIdLogical",method = RequestMethod.DELETE)
	public Message removeByLogic( Long id){

		Message msg = new Message();
		msg.setStatus(service.deleteByIdLogical(id));
		return msg;
	}


	@ResponseBody
	@RequestMapping( value = "/GoodsSpecification/assign2Organs",method = RequestMethod.POST)
	public Message assign2Organs(@RequestBody Assign2OrgansVO assign2Organs){
		Message msg = new Message();
		msg.setStatus(service.assign(assign2Organs));
		return msg;
	}

	@ResponseBody
	@RequestMapping( value = "/GoodsSpecification/assign2Organ",method = RequestMethod.POST)
	public Message assign2Organ(@RequestBody Assign2OrganVO assign2Organ){
		Message msg = new Message();
		msg.setStatus(service.assign(assign2Organ));
		return msg;
	}


}
